/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import vo.PropertiesVO;
import ws.transaction.TransactionResult;
import ws.transaction.TransactionResultWS;
import ws.transaction.TransactionResultWS_Service;

/**
 *
 * @author julianDavidPG
 */
public class TransactionResultServiceControl {
    
    private static final String HOST = "TRANSACTION_HOST";
    private static final String PORT = "TRANSACTION_PORT";
    private static final String RESOURCE = "TRANSACTION_RESOURCE";
    private String serviceLocation;
    private URL url = null;

    public TransactionResultServiceControl() {
        try {
            PropertiesControl.setHOST(HOST);
            PropertiesControl.setPORT(PORT);
            PropertiesControl.setRESOURCE(RESOURCE);
            PropertiesVO p = PropertiesControl.localProperties();
            serviceLocation = "http://" + p.getHost() + ":" + p.getPort().toString() + p.getResource();
            url = new URL(serviceLocation);
        } catch (MalformedURLException malformedURLException) {
            System.out.println("direccion invalida");
        } catch (IOException e) {
            System.out.println("ARCHIVO PROPERTIES FALLO");
            serviceLocation = "http://localhost:8080/Reports/Reports?WSDL";
            try {
                url = new URL(serviceLocation);
            } catch (MalformedURLException ex) {
                System.out.println("direccion invalida");
                Logger.getLogger(LoginServiceControl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void insert() {
        TransactionResultWS_Service service = new TransactionResultWS_Service(url);
        TransactionResultWS port = service.getTransactionResultWSPort();
        port.insert();
    }

    public void startRevision(String fileId) {
        TransactionResultWS_Service service = new TransactionResultWS_Service(url);
        TransactionResultWS port = service.getTransactionResultWSPort();
        port.startRevision(fileId);
    }

    public List<TransactionResult> transactionResultByFile(String fileId) {
        TransactionResultWS_Service service = new TransactionResultWS_Service(url);
        TransactionResultWS port = service.getTransactionResultWSPort();
        return port.transactionResultByFile(fileId);
    }   
}
